﻿using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using static WpfAGVSystem.Common.EnumDefinitions;
using WpfAGVSystem.Common;

namespace WpfAGVSystem.ViewModels
{
	public class DeviceViewModel : BindableBase
	{
        private bool Isbig = false;
        private SettingPara Setting;
        private TaskMgr TaskMgr;
        public string DeviceName { get; set; }
        public string  DeviceID { get; set; }
        public Visibility ViewVisibility { get; set; }
        public DeviceTypeEnum DeviceTypeEnum { get; set; }
        public DeviceTypeClass DeviceTypeClass { get; set; }
        public DelegateCommand MouseDoubleClick { get; private set; }
        public DelegateCommand CheckTaskCmd { get; private set; }

        public string DeviceStatus { get; set; } = "未占用";
        public Brush BackgroundBrush { get; set; } = ColorProcess.UnOccupyed;
        public int InterfaceMapType { get; set; } = 0;
        private Point location;
        public Point Location
        {
            get { return location; }
            set
            {
                location = value;
                Top = (location.Y - Height / 2) + InterfaceMapType * Setting.MapActualHeight;
                Left = location.X - Width / 2;
            }
        }
        public double Height { get; set; }
        public double Width { get; set; }
        public Size bigSize = new Size(200, 150);
        public Size smallSize = new Size(30, 25);
        public double Left { get; private set; }
        public double Top { get; private set; }
        public int ZIndex { get; set; }
        public bool isOccupy
        {
            set
            {
                if (value)
                {
                    BackgroundBrush = ColorProcess.Occupyed;
                    DeviceStatus = "已占用";
                }
                else
                {
                    BackgroundBrush = ColorProcess.UnOccupyed;
                    DeviceStatus = "未占用";
                }
            }
        }
        public DeviceViewModel(SettingPara setting , TaskMgr taskMgr)
        {
            Setting = setting;
            TaskMgr = taskMgr;
            MouseDoubleClick = new DelegateCommand(() => {
                if (Isbig)
                {
                    Width = smallSize.Width;
                    Height = smallSize.Height;
                    ZIndex = 98;
                    Isbig = false;
                }
                else 
                {
                    Width = bigSize.Width;
                    Height = bigSize.Height;
                    ZIndex = int.MaxValue;
                    Isbig = true;
                }
            });
            CheckTaskCmd = new DelegateCommand(() => {
                if (DeviceTypeClass.DeviceStation_EF.TarTaskType != 0)
                {
                    TaskMgr.CreatTask(DeviceTypeClass.DeviceStation_EF.Deviceid, DeviceTypeClass.DeviceStation_EF.TarTaskType, DeviceTypeClass.DeviceStation_EF.Station, DeviceTypeClass.DeviceStation_EF.Flow);
                }
            });
        }
    }
}
